home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / scheme / pcscheme / geneva / sources.exe / SAMPLES / DOCTOR.S < prev    next >
Encoding:
Text File  |  1993-11-30  |  53.9 KB  |  1,593 lines

  1. ;* DOCTOR.S
  2. ;************************************************************************
  3. ;*                                    *
  4. ;*        PC Scheme/Geneva 4.00 Scheme code            *
  5. ;*                                    *
  6. ;* (c) 1985-1988 by Texas Instruments, Inc. See COPYRIGHT.TXT        *
  7. ;* (c) 1992 by L. Bartholdi & M. Vuilleumier, University of Geneva    *
  8. ;*                                    *
  9. ;*----------------------------------------------------------------------*
  10. ;*                                    *
  11. ;*            ELISA: The Psychiatrist                *
  12. ;*                                    *
  13. ;*----------------------------------------------------------------------*
  14. ;*                                    *
  15. ;* Created by:            Date: 19                *
  16. ;* Revision history:                            *
  17. ;* - 18 Jun 92:    Renaissance (Borland Compilers, ...)            *
  18. ;*                                    *
  19. ;*                    ``In nomine omnipotentii dei''    *
  20. ;************************************************************************
  21.  
  22. ;;; doctor.el --- psychological help for frustrated users.
  23.  
  24. ;; Copyright (C) 1985, 1987 Free Software Foundation, Inc.
  25.  
  26. ;; Maintainer: FSF
  27. ;; Keywords: games
  28.  
  29. ;; This file is part of GNU Emacs.
  30.  
  31. ;; GNU Emacs is free software; you can redistribute it and/or modify
  32. ;; it under the terms of the GNU General Public License as published by
  33. ;; the Free Software Foundation; either version 2, or (at your option)
  34. ;; any later version.
  35.  
  36. ;; GNU Emacs is distributed in the hope that it will be useful,
  37. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  38. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  39. ;; GNU General Public License for more details.
  40.  
  41. ;; You should have received a copy of the GNU General Public License
  42. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  43. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  44.  
  45. ;;; Commentary:
  46.  
  47. ;; The single entry point `doctor', simulates a Rogerian analyst using
  48. ;; phrase-production techniques similar to the classic ELIZA demonstration
  49. ;; of pseudo-AI.
  50.  
  51. ;;; Code:
  52.  
  53. (define (doctor-cadr x) (car (cdr x)))
  54. (define (doctor-caddr x) (car (cdr (cdr x))))
  55. (define (doctor-cddr x) (cdr (cdr x)))
  56.  
  57. (define (doctor-substring string start . end)
  58.   (if (null? end)
  59.       (set! end (string-length string))
  60.       (set! end (car end)))
  61.   (if (negative? end)
  62.       (set! end (+ (string-length string) end)))
  63.   (if (negative? start)
  64.       (set! start (+ (string-length string) start)))
  65.   (substring string start end))
  66.  
  67. (macro while
  68.   (lambda (expr)
  69.     (let ((label (gensym)))
  70.       `(LET ,label ()
  71.      (WHEN ,(cadr expr) ,@(cddr expr) (,label))))))
  72.  
  73. (define (insert . s) (map display s))
  74. (define (capitalize s)
  75.   (list->string (map char-upcase (string->list s))))
  76.  
  77. (define (// x) x)
  78.  
  79. (macro $
  80.   (lambda (expr)
  81.     (let ((what (cadr expr)))
  82.       "quoted arg form of doctor-$"
  83.       (list 'DOCTOR-$ (list 'QUOTE what)))))
  84.  
  85. (define (doctor-$ what)
  86.   "Return the car of a list, rotating the list each time"
  87.   (let* ((lookup-code (compile `(access XXX ,user-initial-environment)))
  88.      (doctor-lookup
  89.        (lambda (name)
  90.          (set-car! (member 'XXX (cadddr lookup-code)) name)
  91.          (%execute lookup-code)))
  92.      (vv (doctor-lookup what))
  93.      (first (car vv)))
  94.     (set-cdr! (last-pair vv) (list first))
  95.     (set-car! vv (cadr vv))
  96.     (set-cdr! vv (cddr vv))
  97.     first))
  98.  
  99. (define (doctor-mode)
  100.   "Major mode for running the Doctor (Eliza) program.
  101. Like Text mode with Auto Fill mode
  102. except that RET when point is after a newline, or LFD at any time,
  103. reads the sentence before point, and prints the Doctor's answer."
  104.   (doctor-type '(I AM THE PSYCHOTHERAPIST |.|
  105.          ($ please) ($ describe) YOUR ($ problems) |.|
  106.          EACH TIME YOU ARE FINISHED |TALKING,| TYPE |<RET>.|))
  107.   (insert #\NEWLINE))
  108.  
  109. (define (make-doctor-variables)
  110.   (set! (access monosyllables user-initial-environment)
  111.     "
  112.      Your attitude at the end of the session was wholly unacceptable.
  113.      Please try to come back next time with a willingness to speak more
  114.      freely. If you continue to refuse to talk openly, there is little
  115.      I can do to help!
  116. ")
  117.   (set! (access typos user-initial-environment)
  118.     (mapcar (lambda (x)
  119.           (putprop (car x) (doctor-cadr x) 'DOCTOR-CORRECTION)
  120.           (putprop (doctor-cadr x) (doctor-caddr x) 'DOCTOR-EXPANSION)
  121.           (car x))
  122.         '((THEYLL |THEY'LL| (THEY WILL))
  123.           (THEYRE |THEY'RE| (THEY ARE))
  124.           (HES |HE'S| (HE IS))
  125.           (HE7S |HE'S| (HE IS))
  126.           (IM |I'M| (YOU ARE))
  127.           (I7M |I'M| (YOU ARE))
  128.           (ISA |IS A| (IS A))
  129.           (THIER THEIR (THEIR))
  130.           (DONT |DON'T| (DO NOT))
  131.           (DON7T |DON'T| (DO NOT))
  132.           (YOU7RE |YOU'RE| (I AM))
  133.           (YOU7VE |YOU'VE| (I HAVE))
  134.           (YOU7LL |YOU'LL| (I WILL)))))
  135.   (set! (access found user-initial-environment) #F)
  136.   (set! (access owner user-initial-environment) #F)
  137.   (set! (access history user-initial-environment) #F)
  138.   (set! (access *debug* user-initial-environment) #F)
  139.   (set! (access inter user-initial-environment)
  140.     '((|WELL,|)
  141.       (HMMM |... SO,|)
  142.       (SO)
  143.       (|...AND|)
  144.       (THEN)))
  145.   (set! (access continue user-initial-environment)
  146.     '((CONTINUE)
  147.       (PROCEED)
  148.       (GO ON)
  149.       (KEEP GOING) ))
  150.   (set! (access relation user-initial-environment)
  151.     '((YOUR RELATIONSHIP WITH)
  152.       (SOMETHING YOU REMEMBER ABOUT)
  153.       (YOUR FEELINGS TOWARD)
  154.       (SOME EXPERIENCES YOU HAVE HAD WITH)
  155.       (HOW YOU FEEL ABOUT)))
  156.   (set! (access fears user-initial-environment) '( (($ whysay) YOU ARE ($ afraidof) (// feared) ?)
  157.          (YOU SEEM TERRIFIED BY (// feared) |.|)
  158.          (WHEN DID YOU FIRST FEEL ($ afraidof) (// feared) ?) ))
  159.   (set! (access sure user-initial-environment) '((SURE) (POSITIVE) (CERTAIN) (ABSOLUTELY SURE)))
  160.   (set! (access afraidof user-initial-environment) '( (AFRAID OF) (FRIGHTENED BY) (SCARED OF) ))
  161.   (set! (access areyou user-initial-environment) '( (ARE YOU) (HAVE YOU BEEN) (HAVE YOU BEEN) ))
  162.   (set! (access isrelated user-initial-environment) '( (HAS SOMETHING TO DO WITH) (IS RELATED TO)
  163.              (COULD BE THE REASON FOR) (IS CAUSED BY) (IS BECAUSE OF)))
  164.   (set! (access arerelated user-initial-environment) '((HAVE SOMETHING TO DO WITH) (ARE RELATED TO)
  165.              (COULD HAVE CAUSED) (COULD BE THE REASON FOR) (ARE CAUSED BY)
  166.              (ARE BECAUSE OF)))
  167.   (set! (access moods user-initial-environment) '( (($ areyou) (// found) OFTEN ?)
  168.          (WHAT CAUSES YOU TO BE (// found) ?)
  169.          (($ whysay) YOU ARE (// found) ?) ))
  170.   (set! (access maybe user-initial-environment)
  171.     '((MAYBE)
  172.       (PERHAPS)
  173.       (POSSIBLY)))
  174.   (set! (access whatwhen user-initial-environment)
  175.     '((WHAT HAPPENED WHEN)
  176.       (WHAT WOULD HAPPEN IF)))
  177.   (set! (access hello user-initial-environment)
  178.     '((HOW DO YOU DO ?) (HELLO |.|) (HOWDY!) (HELLO |.|) (HI |.|) (HI THERE |.|)))
  179.   (set! (access drnk user-initial-environment)
  180.     '((DO YOU DRINK A LOT OF (// found) ?)
  181.       (DO YOU GET DRUNK OFTEN ?)
  182.       (($ describe) YOUR DRINKING HABITS |.|) )) 
  183.   (set! (access drugs user-initial-environment) '( (DO YOU USE (// found) OFTEN ?) (($ areyou)
  184.                          ADDICTED TO (// found) ?) (DO YOU REALIZE THAT DRUGS CAN
  185.                          BE VERY HARMFUL ?) (($ maybe) YOU SHOULD TRY TO QUIT USING (// found)
  186.                          |.|)))
  187.   (set! (access whywant user-initial-environment) '( (($ whysay) (// subj) MIGHT ($ want) (// obj) ?)
  188.            (HOW DOES IT FEEL TO WANT ?)
  189.            (WHY SHOULD (// subj) GET (// obj) ?)
  190.            (WHEN DID (// subj) FIRST ($ want) (// obj) ?)
  191.            (($ areyou) OBSESSED WITH (// obj) ?)
  192.            (WHY SHOULD I GIVE (// obj) TO (// subj) ?)
  193.            (HAVE YOU EVER GOTTEN (// obj) ?) ))
  194.   (set! (access canyou user-initial-environment) '((OF COURSE I CAN |.|)
  195.          (WHY SHOULD I ?)
  196.          (WHAT MAKES YOU THINK I WOULD EVEN WANT TO ?)
  197.          (I AM THE DOCTOR\, I CAN DO ANYTHING I DAMN PLEASE |.|)
  198.          (NOT |REALLY,| |IT'S| NOT UP TO ME |.|)
  199.          (|DEPENDS,| HOW IMPORTANT IS IT ?)
  200.          (I |COULD,| BUT I |DON'T| THINK IT WOULD BE A WISE THING TO DO |.|)
  201.          (CAN YOU ?)
  202.          (MAYBE I |CAN,| MAYBE I |CAN'T| |...|)
  203.          (I |DON'T| THINK I SHOULD DO THAT |.|)))
  204.   (set! (access want user-initial-environment) '( (WANT) (DESIRE) (WISH) (WANT) (HOPE) ))
  205.   (set! (access shortlst user-initial-environment)
  206.     '((CAN YOU ELABORATE ON THAT ?)
  207.       (($ please) CONTINUE |.|)
  208.       (GO |ON,| |DON'T| BE AFRAID |.|)
  209.       (I NEED A LITTLE MORE DETAIL PLEASE |.|)
  210.       (|YOU'RE| BEING A BIT |BRIEF,| ($ PLEASE) GO INTO DETAIL |.|)
  211.       (CAN YOU BE MORE EXPLICIT ?)
  212.       (AND ?)
  213.       (($ PLEASE) GO INTO MORE DETAIL ?)
  214.       (YOU |AREN'T| BEING VERY TALKATIVE TODAY!)
  215.       (IS THAT ALL THERE IS TO IT ?)
  216.       (WHY MUST YOU RESPOND SO BRIEFLY ?)))
  217.  
  218.   (set! (access famlst user-initial-environment)
  219.     '((TELL ME ($ something) ABOUT (// owner) FAMILY |.|)
  220.       (YOU SEEM TO DWELL ON (// owner) FAMILY |.|)
  221.       (($ areyou) HUNG UP ON (// owner) FAMILY ?)))
  222.   (set! (access huhlst user-initial-environment)
  223.     '((($ whysay) (// sent) ?)
  224.       (IS IT BECAUSE OF ($ things) THAT YOU SAY (// sent) ?) ))
  225.   (set! (access longhuhlst user-initial-environment)
  226.     '((($ whysay) THAT ?)
  227.       (I |DON'T| UNDERSTAND |.|)
  228.       (($ thlst))
  229.       (($ areyou) ($ afraidof) THAT ?)))
  230.   (set! (access feelings-about user-initial-environment)
  231.     '((FEELINGS ABOUT)
  232.       (APREHENSIONS TOWARD)
  233.       (THOUGHTS ON)
  234.       (EMOTIONS TOWARD)))
  235.   (set! (access random-adjective user-initial-environment)
  236.     '((VIVID)
  237.       (EMOTIONALLY STIMULATING)
  238.       (EXCITING)
  239.       (BORING)
  240.       (INTERESTING)
  241.       (RECENT)
  242.       (RANDOM)   ;How can we omit this?
  243.       (UNUSUAL)
  244.       (SHOCKING)
  245.       (EMBARRASSING)))
  246.   (set! (access whysay user-initial-environment)
  247.     '((WHY DO YOU SAY)
  248.       (WHAT MAKES YOU BELIEVE)
  249.       (ARE YOU SURE THAT)
  250.       (DO YOU REALLY THINK)
  251.       (WHAT MAKES YOU THINK) ))
  252.   (set! (access isee user-initial-environment)
  253.     '((I SEE |...|)
  254.       (|YES,|)
  255.       (I UNDERSTAND |.|)
  256.       (OH |.|) ))
  257.   (set! (access please user-initial-environment) 
  258.     '((|PLEASE,|)
  259.       (I WOULD APPRECIATE IT IF YOU WOULD)
  260.       (PERHAPS YOU COULD)
  261.       (|PLEASE,|)
  262.       (WOULD YOU PLEASE)
  263.       (WHY |DON'T| YOU)
  264.       (COULD YOU)))
  265.   (set! (access bye user-initial-environment)
  266.     '((MY SECRETARY WILL SEND YOU A BILL |.|)
  267.       (BYE BYE |.|)
  268.       (SEE YA |.|)
  269.       (|OK,| TALK TO YOU SOME OTHER TIME |.|)
  270.       (TALK TO YOU LATER |.|)
  271.       (|OK,| HAVE FUN |.|)
  272.       (CIAO |.|)))
  273.   (set! (access something user-initial-environment)
  274.     '((SOMETHING)
  275.       (MORE)
  276.       (HOW YOU FEEL)))
  277.   (set! (access things user-initial-environment) 
  278.     '(;(YOUR INTERESTS IN COMPUTERS)   ;; let's make this less computer oriented
  279.       ;(THE MACHINES YOU USE)
  280.       (YOUR PLANS)
  281.       ;(YOUR USE OF COMPUTERS)
  282.       (YOUR LIFE)
  283.       ;(OTHER MACHINES YOU USE)
  284.       (THE PEOPLE YOU HANG AROUND WITH)
  285.       ;(COMPUTERS YOU LIKE)
  286.       (PROBLEMS AT SCHOOL)
  287.       (ANY HOBBIES YOU HAVE)
  288.       ;(OTHER COMPUTERS YOU USE)
  289.       (YOUR SEX LIFE)
  290.       (HANGUPS YOU HAVE)
  291.       (YOUR INHIBITIONS)
  292.       (SOME PROBLEMS IN YOUR CHILDHOOD)
  293.       ;(KNOWLEDGE OF COMPUTERS)
  294.       (SOME PROBLEMS AT HOME)))
  295.   (set! (access describe user-initial-environment)
  296.     '((DESCRIBE)
  297.       (TELL ME ABOUT)
  298.       (TALK ABOUT)
  299.       (DISCUSS)
  300.       (TELL ME MORE ABOUT)
  301.       (ELABORATE ON)))
  302.   (set! (access ibelieve user-initial-environment) 
  303.     '((I BELIEVE) (I THINK) (I HAVE A FEELING) (IT SEEMS TO ME THAT)
  304.       (IT LOOKS LIKE)))
  305.   (set! (access problems user-initial-environment) '( (PROBLEMS)
  306.             (INHIBITIONS)
  307.             (HANGUPS)
  308.             (DIFFICULTIES)
  309.             (ANXIETIES)
  310.             (FRUSTRATIONS) ))
  311.   (set! (access bother user-initial-environment)
  312.     '((DOES IT BOTHER YOU THAT)
  313.       (ARE YOU ANNOYED THAT)
  314.       (DID YOU EVER REGRET)
  315.       (ARE YOU SORRY)
  316.       (arE YOU SATISFIED WITH THE FACT THAT)))
  317.   (set! (access machlst user-initial-environment) 
  318.     '((YOU HAVE YOUR MIND ON (// found) |,| IT SEEMS |.|)
  319.       (YOU THINK TOO MUCH ABOUT (// found) |.|)
  320.       (YOU SHOULD TRY TAKING YOUR MIND OFF OF (// found) |.|)
  321.       (ARE YOU A COMPUTER HACKER ?)))
  322.   (set! (access qlist user-initial-environment)
  323.     '((WHAT DO YOU THINK ?)
  324.       (|I'LL| ASK THE |QUESTIONS,| IF YOU |DON'T| MIND!)
  325.       (I COULD ASK THE SAME THING MYSELF |.|)
  326.       (($ please) ALLOW ME TO DO THE QUESTIONING |.|)
  327.       (I HAVE ASKED MYSELF THAT QUESTION MANY TIMES |.|)
  328.       (($ please) TRY TO ANSWER THAT QUESTION YOURSELF |.|)))
  329.   (set! (access elist user-initial-environment)
  330.     '((($ please) TRY TO CALM YOURSELF |.|)
  331.       (YOU SEEM VERY EXCITED |.| RELAX |.| ($ please) ($ describe) ($ things)
  332.            |.|)
  333.       (|YOU'RE| BEING VERY EMOTIONAL |.| CALM DOWN |.|)))
  334.   (set! (access foullst user-initial-environment)
  335.     '((($ please) WATCH YOUR TONGUE!)
  336.       (($ please) AVOID SUCH UNWHOLESOME THOUGHTS |.|)
  337.       (($ please) GET YOUR MIND OUT OF THE GUTTER |.|)
  338.       (SUCH LEWDNESS IS NOT APPRECIATED |.|)))
  339.   (set! (access deathlst user-initial-environment)
  340.     '((THIS IS NOT A HEALTHY WAY OF THINKING |.|)
  341.       (($ bother) |YOU,| |TOO,| MAY DIE SOMEDAY ?)
  342.       (I AM WORRIED BY YOUR OBSESSION WITH THIS TOPIC!)
  343.       (DID YOU WATCH A LOT OF CRIME AND VIOLENCE ON TELEVISION AS A CHILD ?))
  344.     )
  345.   (set! (access sexlst user-initial-environment) 
  346.     '((($ areyou) ($ afraidof) SEX ?)
  347.       (($ describe) ($ something) ABOUT YOUR SEXUAL HISTORY |.|)
  348.       (($ please) ($ describe) YOUR SEX LIFE |...|)
  349.       (($ describe) YOUR ($ feelings-about) YOUR SEXUAL PARTNER |.|)
  350.       (($ describe) YOUR MOST ($ random-adjective) SEXUAL EXPERIENCE |.|)
  351.       (($ areyou) SATISFIED WITH (// lover) |...| ?)))
  352.   (set! (access neglst user-initial-environment)
  353.     '((WHY NOT ?)
  354.       (($ bother) I ASK THAT ?)
  355.       (WHY NOT ?)
  356.       (WHY NOT ?)
  357.       (HOW COME ?)
  358.       (($ bother) I ASK THAT ?)))
  359.   (set! (access beclst user-initial-environment) '(
  360.          (IS IT BECAUSE (// sent) THAT YOU CAME TO ME ?)
  361.          (($ bother) (// sent) ?)
  362.          (WHEN DID YOU FIRST KNOW THAT (// sent) ?)
  363.          (IS THE FACT THAT (// sent) THE REAL REASON ?)
  364.          (DOES THE FACT THAT (// sent) EXPLAIN ANYTHING ELSE ?)
  365.          (($ areyou) ($ sure) (// sent) ? ) ))
  366.   (set! (access shortbeclst user-initial-environment) '(
  367.               (($ bother) I ASK YOU THAT ?)
  368.               (|THAT'S| NOT MUCH OF AN ANSWER!)
  369.               (($ inter) WHY |WON'T| YOU TALK ABOUT IT ?)
  370.               (SPEAK UP!)
  371.               (($ areyou) ($ afraidof) TALKING ABOUT IT ?)
  372.               (|DON'T| BE ($ afraidof) ELABORATING |.|)
  373.               (($ please) GO INTO MORE DETAIL |.|)))
  374.   (set! (access thlst user-initial-environment) '(
  375.         (($ maybe) ($ things) ($ arerelated) THIS |.|)
  376.         (IS IT BECAUSE OF ($ things) THAT YOU ARE GOING THROUGH ALL THIS ?)
  377.         (HOW DO YOU RECONCILE ($ things) ? )
  378.         (($ maybe) THIS ($ isrelated) ($ things) ?) ))
  379.   (set! (access remlst user-initial-environment) '( (EARLIER YOU SAID ($ history) ?)
  380.           (YOU MENTIONED THAt ($ history) ?)
  381.           (($ whysay) ($ history) ? ) ))
  382.   (set! (access toklst user-initial-environment)
  383.     '((IS THIS HOW YOU RELAX ?)
  384.       (HOW LONG HAVE YOU BEEN SMOKING    GRASS ?)
  385.       (($ areyou) ($ afraidof) OF BEING DRAWN TO USING HARDER STUFF ?)))
  386.   (set! (access states user-initial-environment)
  387.     '((DO YOU GET (// found) OFTEN ?)
  388.       (DO YOU ENJOY BEING (// found) ?)
  389.       (WHAT MAKES YOU (// found) ?)
  390.       (HOW OFTEN ($ areyou) (// found) ?)
  391.       (WHEN WERE YOU LAST (// found) ?)))
  392.   (set! (access replist user-initial-environment) 
  393.     '((I . (YOU))
  394.       (MY . (YOUR))
  395.       (ME . (YOU))
  396.       (YOU . (ME))
  397.       (YOUR . (MY))
  398.       (MINE . (YOURS))
  399.       (YOURS . (MINE))
  400.       (OUR . (YOUR))
  401.       (OURS . (YOURS))
  402.       (WE . (YOU))
  403.       (DUNNO . (DO NOT KNOW))
  404. ;;      (YES . ())
  405.       (|NO,| . ())
  406.       (|YES,| . ())
  407.       (YA . (I))
  408.       (AINT . (AM NOT))
  409.       (WANNA . (WANT TO))
  410.       (GIMME . (GIVE ME))
  411.       (GOTTA . (HAVE TO))
  412.       (GONNA . (GOING TO))
  413.       (NEVER . (NOT EVER))
  414.       (|DOESN'T| . (DOES NOT))
  415.       (|DON'T| . (DO NOT))
  416.       (|AREN'T| . (ARE NOT))
  417.       (|ISN'T| . (IS NOT))
  418.       (|WON'T| . (WILL NOT))
  419.       (|CAN'T| . (CANNOT))
  420.       (|HAVEN'T| . (HAVE NOT))
  421.       (|I'M| . (YOU ARE))
  422.       (OURSELVES . (YOURSELVES))
  423.       (MYSELF . (YOURSELF))
  424.       (YOURSELF . (MYSELF))
  425.       (|YOU'RE| . (I AM))
  426.       (|YOU'VE| . (I HAVE))
  427.       (|I'VE| . (YOU HAVE))
  428.       (|I'LL| . (YOU WILL))
  429.       (|YOU'LL| . (I SHALL))
  430.       (|I'D| . (YOU WOULD))
  431.       (|YOU'D| . (I WOULD))
  432.       (HERE . (THERE))
  433.       (PLEASE . ())
  434.       (|EH,| . ())
  435.       (EH . ())
  436.       (|OH,| . ())
  437.       (OH . ())
  438.       (|SHOULDN'T| . (SHOULD NOT))
  439.       (|WOULDN'T| . (WOULD NOT))
  440.       (|WON'T| . (WILL NOT))
  441.       (|HASN'T| . (HAS NOT))))
  442.   (set! (access stallmanlst user-initial-environment) '(
  443.               (($ describe) YOUR ($ feelings-about) HIM |.|)
  444.               (($ areyou) A FRIEND OF STALLMAN ?)
  445.               (($ bother) STALLMAN IS ($ random-adjective) ?)
  446.               (($ ibelieve) YOU ARE ($ afraidof) HIM |.|)))
  447.   (set! (access schoollst user-initial-environment) '(
  448.             (($ describe) YOUR (// found) |.|)
  449.             (($ bother) YOUR GRADES COULD ($ improve) ?)
  450.             (($ areyou) ($ afraidof) (// found) ?)
  451.             (($ maybe) THIS ($ isrelated) TO YOUR ATTITUDE |.|)
  452.             (($ areyou) ABSENT OFTEN ?)
  453.             (($ maybe) yOU SHOULD STUDY ($ something) |.|)))
  454.   (set! (access improve user-initial-environment) '((IMPROVE) (BE BETTER) (BE IMPROVED) (BE HIGHER)))
  455.   (set! (access elizalst user-initial-environment) '(
  456.            (($ areyou) ($ sure) ?)
  457.            (($ ibelieve) YOU HAVE ($ problems) WITH (// found) |.|)
  458.            (($ whysay) (// sent) ?)))
  459.   (set! (access sportslst user-initial-environment) '(
  460.             (TELL ME ($ something) ABOUT (// found) |.|)
  461.             (($ describe) ($ relation) (// found) |.|)
  462.             (DO YOU FIND (// found) ($ random-adjective) ?)))
  463.   (set! (access mathlst user-initial-environment) '(
  464.           (($ describe) ($ something) ABOUT MATH |.|)
  465.           (($ maybe) YOUR ($ problems) ($ arerelated) (// found) |.|)
  466.           (I |DO'NT| KNOW MUCH (// found) |,| BUT ($ continue)
  467.              ANYWAY |.|)))
  468.   (set! (access zippylst user-initial-environment) '(
  469.            (($ areyou) ZIPPY ?)
  470.            (($ ibelieve) YOU HAVE SOME SERIOUS ($ problems) |.|)
  471.            (($ bother) YOU ARE A PINHEAD ?)))
  472.   (set! (access chatlst user-initial-environment) '(
  473.           (($ maybe) WE COULD CHAT |.|)
  474.           (($ please) ($ describe) ($ something) ABOUT CHAT MODE |.|)
  475.           (($ bother) OUR DISCUSSION IS SO ($ random-adjective) ?)))
  476.   (set! (access abuselst user-initial-environment) '(
  477.            (($ please) TRY TO BE LESS ABUSIVE |.|)
  478.            (($ describe) WHY YOU CALL ME (// found) |.|)
  479.            (|I'VE| HAD ENOUGH OF YOU!)))
  480.   (set! (access abusewords user-initial-environment) '(BORING BOZO CLOWN CLUMSY CRETIN DUMB DUMMY
  481.                 FOOL FOOLISH GNERD GNURD IDIOT JERK
  482.                 LOSE LOSER LOUSE LOUSY LUSE LUSER
  483.                 MORON NERD NURD OAF OAFISH REEK
  484.                 STINK STUPID TOOL TOOLISH TWIT))
  485.   (set! (access howareyoulst user-initial-environment)  '((HOW ARE YOU) (HOWS IT GOING) (HOWS IT GOING EH)
  486.             (|HOW'S| IT GOING) (|HOW'S| IT GOING EH) (HOW GOES IT)
  487.             (WHATS UP) (WHATS NEW) (|WHAT'S| UP) (|WHAT'S| NEW)
  488.             (HOWRE YOU) (|HOW'RE| YOU) (|HOW'S| EVERYTHING)
  489.             (HOW IS EVERYTHING) (HOW DO YOU DO)
  490.             (|HOW'S| IT HANGING) (QUE PASA)
  491.             (HOW ARE YOU DOING) (WHAT DO YOU SAY)))
  492.   (set! (access whereoutp user-initial-environment) '( HUH REMEM RTHING ) )
  493.   (set! (access subj user-initial-environment) #F)
  494.   (set! (access verb user-initial-environment) #F)
  495.   (set! (access obj user-initial-environment) #F)
  496.   (set! (access feared user-initial-environment) #F)
  497.   (set! (access observation-list user-initial-environment) #F)
  498.   (set! (access repetitive-shortness user-initial-environment) '(0 . 0))
  499.   (set! (access **mad** user-initial-environment) #F)
  500.   (set! (access rms-flag user-initial-environment) #F)
  501.   (set! (access eliza-flag user-initial-environment) #F)
  502.   (set! (access zippy-flag user-initial-environment) #F)
  503.   (set! (access lover user-initial-environment) '(YOUR PARTNER))
  504.   (set! (access bak user-initial-environment) #F)
  505.   (set! (access lincount user-initial-environment) 0)
  506.   (set! (access *print-upcase* user-initial-environment) #F)
  507.   (set! (access *print-space* user-initial-environment) #F)
  508.   (set! (access howdyflag user-initial-environment) #F)
  509.   (set! (access object user-initial-environment) #F))
  510.  
  511. ;; Define equivalence classes of words that get treated alike.
  512.  
  513. (define (doctor-meaning x) (getprop x 'DOCTOR-MEANING))
  514.  
  515. (macro doctor-put-meaning
  516.   (lambda (expr)
  517.     (let ((symb (cadr expr))
  518.       (val (caddr expr)))
  519.       "Store the base meaning of a word on the property list."
  520.       `(PUTPROP ',symb ,val 'DOCTOR-MEANING))))
  521.  
  522. (doctor-put-meaning HOWDY 'HOWDY)
  523. (doctor-put-meaning HI 'HOWDY)
  524. (doctor-put-meaning GREETINGS 'HOWDY)
  525. (doctor-put-meaning HELLO 'HOWDY)
  526. (doctor-put-meaning TOPS20 'MACH)
  527. (doctor-put-meaning TOPS-20 'MACH)
  528. (doctor-put-meaning TOPS 'MACH)
  529. (doctor-put-meaning PDP11 'MACH)
  530. (doctor-put-meaning COMPUTER 'MACH)
  531. (doctor-put-meaning UNIX 'MACH)
  532. (doctor-put-meaning MACHINE 'MACH)
  533. (doctor-put-meaning COMPUTERS 'MACH)
  534. (doctor-put-meaning MACHINES 'MACH)
  535. (doctor-put-meaning PDP11S 'MACH)
  536. (doctor-put-meaning FOO 'MACH)
  537. (doctor-put-meaning FOOBAR 'MACH)
  538. (doctor-put-meaning MULTICS 'MACH)
  539. (doctor-put-meaning MACSYMA 'MACH)
  540. (doctor-put-meaning TELETYPE 'MACH)
  541. (doctor-put-meaning LA36 'MACH)
  542. (doctor-put-meaning VT52 'MACH)
  543. (doctor-put-meaning ZORK 'MACH)
  544. (doctor-put-meaning TREK 'MACH)
  545. (doctor-put-meaning STARTREK 'MACH)
  546. (doctor-put-meaning ADVENT 'MACH)
  547. (doctor-put-meaning PDP 'MACH)
  548. (doctor-put-meaning DEC 'MACH)
  549. (doctor-put-meaning COMMODORE 'MACH)
  550. (doctor-put-meaning VIC 'MACH)
  551. (doctor-put-meaning BBS 'MACH)
  552. (doctor-put-meaning MODEM 'MACH)
  553. (doctor-put-meaning BAUD 'MACH)
  554. (doctor-put-meaning MACINTOSH 'MACH)
  555. (doctor-put-meaning VAX 'MACH)
  556. (doctor-put-meaning VMS 'MACH)
  557. (doctor-put-meaning IBM 'MACH)
  558. (doctor-put-meaning PC 'MACH)
  559. (doctor-put-meaning BITCHING 'FOUL)
  560. (doctor-put-meaning SHIT 'FOUL)
  561. (doctor-put-meaning BASTARD 'FOUL)
  562. (doctor-put-meaning DAMN 'FOUL)
  563. (doctor-put-meaning DAMNED 'FOUL)
  564. (doctor-put-meaning HELL 'FOUL)
  565. (doctor-put-meaning SUCK 'FOUL)
  566. (doctor-put-meaning SUCKING 'FOUL)
  567. (doctor-put-meaning SUX 'FOUL)
  568. (doctor-put-meaning ASS 'FOUL)
  569. (doctor-put-meaning WHORE 'FOUL)
  570. (doctor-put-meaning BITCH 'FOUL)
  571. (doctor-put-meaning ASSHOLE 'FOUL)
  572. (doctor-put-meaning SHRINK 'FOUL)
  573. (doctor-put-meaning POT 'TOKE)
  574. (doctor-put-meaning GRASS 'TOKE)
  575. (doctor-put-meaning WEED 'TOKE)
  576. (doctor-put-meaning MARIJUANA 'TOKE)
  577. (doctor-put-meaning ACAPULCO 'TOKE)
  578. (doctor-put-meaning COLUMBIAN 'TOKE)
  579. (doctor-put-meaning TOKIN 'TOKE)
  580. (doctor-put-meaning JOINT 'TOKE)
  581. (doctor-put-meaning TOKE 'TOKE)
  582. (doctor-put-meaning TOKING 'TOKE)
  583. (doctor-put-meaning |TOKIN'| 'TOKE)
  584. (doctor-put-meaning TOKED 'TOKE)
  585. (doctor-put-meaning ROACH 'TOKE)
  586. (doctor-put-meaning PILLS 'DRUG)
  587. (doctor-put-meaning DOPE 'DRUG)
  588. (doctor-put-meaning ACID 'DRUG)
  589. (doctor-put-meaning LSD 'DRUG)
  590. (doctor-put-meaning SPEED 'DRUG)
  591. (doctor-put-meaning HEROIN 'DRUG)
  592. (doctor-put-meaning HASH 'DRUG)
  593. (doctor-put-meaning COCAINE 'DRUG)
  594. (doctor-put-meaning UPPERS 'DRUG)
  595. (doctor-put-meaning DOWNERS 'DRUG)
  596. (doctor-put-meaning LOVES 'LOVES)
  597. (doctor-put-meaning LOVE 'LOVE)
  598. (doctor-put-meaning LOVED 'LOVE)
  599. (doctor-put-meaning HATES 'HATES)
  600. (doctor-put-meaning DISLIKES 'HATES)
  601. (doctor-put-meaning HATE 'HATE)
  602. (doctor-put-meaning HATED 'HATE)
  603. (doctor-put-meaning DISLIKE 'HATE)
  604. (doctor-put-meaning STONED 'STATE)
  605. (doctor-put-meaning DRUNK 'STATE)
  606. (doctor-put-meaning DRUNKEN 'STATE)
  607. (doctor-put-meaning HIGH 'STATE)
  608. (doctor-put-meaning HORNY 'STATE)
  609. (doctor-put-meaning BLASTED 'STATE)
  610. (doctor-put-meaning HAPPY 'STATE)
  611. (doctor-put-meaning PARANOID 'STATE)
  612. (doctor-put-meaning WISH 'DESIRE)
  613. (doctor-put-meaning WISHES 'DESIRE)
  614. (doctor-put-meaning WANT 'DESIRE)
  615. (doctor-put-meaning DESIRE 'DESIRE)
  616. (doctor-put-meaning LIKE 'DESIRE)
  617. (doctor-put-meaning HOPE 'DESIRE)
  618. (doctor-put-meaning HOPES 'DESIRE)
  619. (doctor-put-meaning DESIRES 'DESIRE)
  620. (doctor-put-meaning WANTS 'DESIRE)
  621. (doctor-put-meaning DESIRES 'DESIRE)
  622. (doctor-put-meaning LIKES 'DESIRE)
  623. (doctor-put-meaning NEEDS 'DESIRE)
  624. (doctor-put-meaning NEED 'DESIRE)
  625. (doctor-put-meaning FRUSTRATED 'MOOD)
  626. (doctor-put-meaning DEPRESSED 'MOOD)
  627. (doctor-put-meaning ANNOYED 'MOOD)
  628. (doctor-put-meaning UPSET 'MOOD)
  629. (doctor-put-meaning UNHAPPY 'MOOD)
  630. (doctor-put-meaning EXCITED 'MOOD)
  631. (doctor-put-meaning WORRIED 'MOOD)
  632. (doctor-put-meaning LONELY 'MOOD)
  633. (doctor-put-meaning ANGRY 'MOOD)
  634. (doctor-put-meaning MAD 'MOOD)
  635. (doctor-put-meaning PISSED 'MOOD)
  636. (doctor-put-meaning JEALOUS 'MOOD)
  637. (doctor-put-meaning AFRAID 'FEAR)
  638. (doctor-put-meaning TERRIFIED 'FEAR)
  639. (doctor-put-meaning FEAR 'FEAR)
  640. (doctor-put-meaning SCARED 'FEAR)
  641. (doctor-put-meaning FRIGHTENED 'FEAR)
  642. (doctor-put-meaning VIRGINITY 'SEXNOUN)
  643. (doctor-put-meaning VIRGINS 'SEXNOUN)
  644. (doctor-put-meaning VIRGIN 'SEXNOUN)
  645. (doctor-put-meaning COCK 'SEXNOUN)
  646. (doctor-put-meaning COCKS 'SEXNOUN)
  647. (doctor-put-meaning DICK 'SEXNOUN)
  648. (doctor-put-meaning DICKS 'SEXNOUN)
  649. (doctor-put-meaning CUNT 'SEXNOUN)
  650. (doctor-put-meaning CUNTS 'SEXNOUN)
  651. (doctor-put-meaning PROSTITUTE 'SEXNOUN)
  652. (doctor-put-meaning CONDOM 'SEXNOUN)
  653. (doctor-put-meaning SEX 'SEXNOUN)
  654. (doctor-put-meaning RAPES 'SEXNOUN)
  655. (doctor-put-meaning WIFE 'FAMILY)
  656. (doctor-put-meaning FAMILY 'FAMILY)
  657. (doctor-put-meaning BROTHERS 'FAMILY)
  658. (doctor-put-meaning SISTERS 'FAMILY)
  659. (doctor-put-meaning PARENT 'FAMILY)
  660. (doctor-put-meaning PARENTS 'FAMILY)
  661. (doctor-put-meaning BROTHER 'FAMILY)
  662. (doctor-put-meaning SISTER 'FAMILY)
  663. (doctor-put-meaning FATHER 'FAMILY)
  664. (doctor-put-meaning MOTHER 'FAMILY)
  665. (doctor-put-meaning HUSBAND 'FAMILY)
  666. (doctor-put-meaning SIBLINGS 'FAMILY)
  667. (doctor-put-meaning GRANDMOTHER 'FAMILY)
  668. (doctor-put-meaning GRANDFATHER 'FAMILY)
  669. (doctor-put-meaning MATERNAL 'FAMILY)
  670. (doctor-put-meaning PATERNAL 'FAMILY)
  671. (doctor-put-meaning STAB 'DEATH)
  672. (doctor-put-meaning MURDER 'DEATH)
  673. (doctor-put-meaning MURDERS 'DEATH)
  674. (doctor-put-meaning SUICIDE 'DEATH)
  675. (doctor-put-meaning SUICIDES 'DEATH)
  676. (doctor-put-meaning KILL 'DEATH)
  677. (doctor-put-meaning KILLS 'DEATH)
  678. (doctor-put-meaning DIE 'DEATH)
  679. (doctor-put-meaning DIES 'DEATH)
  680. (doctor-put-meaning DIED 'DEATH)
  681. (doctor-put-meaning DEAD 'DEATH)
  682. (doctor-put-meaning DEATH 'DEATH)
  683. (doctor-put-meaning DEATHS 'DEATH)
  684. (doctor-put-meaning PAIN 'SYMPTOMS)
  685. (doctor-put-meaning ACHE 'SYMPTOMS)
  686. (doctor-put-meaning FEVER 'SYMPTOMS)
  687. (doctor-put-meaning SORE 'SYMPTOMS)
  688. (doctor-put-meaning ACHING 'SYMPTOMS)
  689. (doctor-put-meaning STOMACHACHE 'SYMPTOMS)
  690. (doctor-put-meaning HEADACHE 'SYMPTOMS)
  691. (doctor-put-meaning HURTS 'SYMPTOMS)
  692. (doctor-put-meaning DISEASE 'SYMPTOMS)
  693. (doctor-put-meaning VIRUS 'SYMPTOMS)
  694. (doctor-put-meaning VOMIT 'SYMPTOMS)
  695. (doctor-put-meaning VOMITING 'SYMPTOMS)
  696. (doctor-put-meaning BARF 'SYMPTOMS)
  697. (doctor-put-meaning TOOTHACHE 'SYMPTOMS)
  698. (doctor-put-meaning HURT 'SYMPTOMS)
  699. (doctor-put-meaning RUM 'ALCOHOL)
  700. (doctor-put-meaning GIN 'ALCOHOL)
  701. (doctor-put-meaning VODKA 'ALCOHOL)
  702. (doctor-put-meaning ALCOHOL 'ALCOHOL)
  703. (doctor-put-meaning BOURBON 'ALCOHOL)
  704. (doctor-put-meaning BEER 'ALCOHOL)
  705. (doctor-put-meaning WINE 'ALCOHOL)
  706. (doctor-put-meaning WHISKEY 'ALCOHOL)
  707. (doctor-put-meaning SCOTCH 'ALCOHOL)
  708. (doctor-put-meaning FUCK 'SEXVERB)
  709. (doctor-put-meaning FUCKED 'SEXVERB)
  710. (doctor-put-meaning SCREW 'SEXVERB)
  711. (doctor-put-meaning SCREWING 'SEXVERB)
  712. (doctor-put-meaning FUCKING 'SEXVERB)
  713. (doctor-put-meaning RAPE 'SEXVERB)
  714. (doctor-put-meaning RAPED 'SEXVERB)
  715. (doctor-put-meaning KISS 'SEXVERB)
  716. (doctor-put-meaning KISSING 'SEXVERB)
  717. (doctor-put-meaning KISSES 'SEXVERB)
  718. (doctor-put-meaning SCREWS 'SEXVERB)
  719. (doctor-put-meaning FUCKS 'SEXVERB)
  720. (doctor-put-meaning BECAUSE 'CONJ)
  721. (doctor-put-meaning BUT 'CONJ)
  722. (doctor-put-meaning HOWEVER 'CONJ)
  723. (doctor-put-meaning BESIDES 'CONJ)
  724. (doctor-put-meaning ANYWAY 'CONJ)
  725. (doctor-put-meaning THAT 'CONJ)
  726. (doctor-put-meaning EXCEPT 'CONJ)
  727. (doctor-put-meaning WHY 'CONJ)
  728. (doctor-put-meaning HOW 'CONJ)
  729. (doctor-put-meaning UNTIL 'WHEN)
  730. (doctor-put-meaning WHEN 'WHEN)
  731. (doctor-put-meaning WHENEVER 'WHEN)
  732. (doctor-put-meaning WHILE 'WHEN)
  733. (doctor-put-meaning SINCE 'WHEN)
  734. (doctor-put-meaning RMS 'RMS)
  735. (doctor-put-meaning STALLMAN 'RMS)
  736. (doctor-put-meaning SCHOOL 'SCHOOL)
  737. (doctor-put-meaning SCHOOLS 'SCHOOL)
  738. (doctor-put-meaning SKOOL 'SCHOOL)
  739. (doctor-put-meaning GRADE 'SCHOOL)
  740. (doctor-put-meaning GRADES 'SCHOOL)
  741. (doctor-put-meaning TEACHER 'SCHOOL)
  742. (doctor-put-meaning TEACHERS 'SCHOOL)
  743. (doctor-put-meaning CLASSES 'SCHOOL)
  744. (doctor-put-meaning PROFESSOR 'SCHOOL)
  745. (doctor-put-meaning PROF 'SCHOOL)
  746. (doctor-put-meaning PROFS 'SCHOOL)
  747. (doctor-put-meaning PROFESSORS 'SCHOOL)
  748. (doctor-put-meaning MIT 'SCHOOL)
  749. (doctor-put-meaning EMACS 'ELIZA)
  750. (doctor-put-meaning ELIZA 'ELIZA)
  751. (doctor-put-meaning LIZA 'ELIZA)
  752. (doctor-put-meaning ELISA 'ELIZA)
  753. (doctor-put-meaning WEIZENBAUM 'ELIZA)
  754. (doctor-put-meaning DOKTOR 'ELIZA)
  755. (doctor-put-meaning ATHLETICS 'SPORTS)
  756. (doctor-put-meaning BASEBALL 'SPORTS)
  757. (doctor-put-meaning BASKETBALL 'SPORTS)
  758. (doctor-put-meaning FOOTBALL 'SPORTS)
  759. (doctor-put-meaning FRISBEE 'SPORTS)
  760. (doctor-put-meaning GYM 'SPORTS)
  761. (doctor-put-meaning GYMNASTICS 'SPORTS)
  762. (doctor-put-meaning HOCKEY 'SPORTS)
  763. (doctor-put-meaning LACROSSE 'SPORTS)
  764. (doctor-put-meaning SOCCER 'SPORTS)
  765. (doctor-put-meaning SOFTBALL 'SPORTS)
  766. (doctor-put-meaning SPORTS 'SPORTS)
  767. (doctor-put-meaning SWIMMING 'SPORTS)
  768. (doctor-put-meaning SWIM 'SPORTS)
  769. (doctor-put-meaning TENNIS 'SPORTS)
  770. (doctor-put-meaning VOLLEYBALL 'SPORTS)
  771. (doctor-put-meaning MATH 'MATH)
  772. (doctor-put-meaning MATHEMATICS 'MATH)
  773. (doctor-put-meaning MATHEMATICAL 'MATH)
  774. (doctor-put-meaning THEOREM 'MATH)
  775. (doctor-put-meaning AXIOM 'MATH)
  776. (doctor-put-meaning LEMMA 'MATH)
  777. (doctor-put-meaning ALGEBRA 'MATH)
  778. (doctor-put-meaning ALGEBRAIC 'MATH)
  779. (doctor-put-meaning TRIG 'MATH)
  780. (doctor-put-meaning TRIGONOMETRY 'MATH)
  781. (doctor-put-meaning TRIGONOMETRIC 'MATH)
  782. (doctor-put-meaning GEOMETRY 'MATH)
  783. (doctor-put-meaning GEOMETRIC 'MATH)
  784. (doctor-put-meaning CALCULUS 'MATH)
  785. (doctor-put-meaning ARITHMETIC 'MATH)
  786. (doctor-put-meaning ZIPPY 'ZIPPY)
  787. (doctor-put-meaning ZIPPY 'ZIPPY)
  788. (doctor-put-meaning PINHEAD 'ZIPPY)
  789. (doctor-put-meaning CHAT 'CHAT)
  790.  
  791. (define (doctor-read-print)
  792.   "top level loop"
  793.   (let ((sent (doctor-readin)))
  794.     (set! lincount (1+ lincount))
  795.     (doctor-doc sent)
  796.     (set! bak sent)))
  797.  
  798. (define (doctor-readin)
  799.   "Read a sentence.  Return it as a list of words."
  800.   (let loop ((sentence '()))
  801.     (let ((next (doctor-read-token)))
  802.       (if (eof-object? next)
  803.       sentence
  804.       (loop (append sentence (list next)))))))
  805.  
  806. (define doctor-read-token)
  807. (let ((read-buffer #F)
  808.       (read-string ""))
  809.   (set! doctor-read-token
  810.     (lambda ()
  811.       "read one word from buffer"
  812.       (when (null? read-buffer)
  813.     (set! read-string (read-line 'CONSOLE))
  814.     (set! read-buffer (open-input-string read-string)))
  815.       (let loop ((buf '()))
  816.     (let ((new (read-char read-buffer)))
  817.       (cond ((and (eof-object? new) (null? buf))
  818.          (close-input-port read-buffer)
  819.          (if (not (string-null? read-string))
  820.              (read-line 'CONSOLE))    ; bug
  821.          (set! read-buffer #F)
  822.          new)
  823.         ((and (char-whitespace? new) (null? buf))
  824.          (doctor-read-token))
  825.         ((or (char-whitespace? new)
  826.              (eof-object? new)
  827.              (member new '(#\? #\. #\: #\, #\; #\!)))
  828.          (unread-char)
  829.          (string->symbol (capitalize (list->string (reverse! buf)))))
  830.         (else (loop (cons new buf)))))))))
  831.  
  832. ;; Main processing function for sentences that have been read.
  833.  
  834. (define (doctor-doc sent)
  835.   (set! (access sent user-initial-environment) sent)
  836.   (private-doctor-doc))
  837. (define (private-doctor-doc)
  838.   (cond
  839.    ((equal? sent '(FOO))
  840.     (doctor-type '(BAR! ($ please) ($ continue))))
  841.    ((member sent howareyoulst)
  842.     (doctor-type '(|I'M| OK |.|  ($ describe) YOURSELF |.|)))
  843.    ((or (member sent '((GOOD BYE) (SEE YOU LATER) (I QUIT) (SO LONG)
  844.                (GO AWAY) (GET LOST)))
  845.     (memq (car sent)
  846.           '(BYE HALT BREAK QUIT DONE EXIT GOODBYE 
  847.             |BYE,| STOP PAUSE |GOODBYE,| STOP PAUSE)))
  848.     (doctor-type ($ bye)))
  849.    ((and (eq? (car sent) 'YOU)
  850.      (memq (doctor-cadr sent) abusewords))
  851.     (set! found (doctor-cadr sent))
  852.     (doctor-type ($ abuselst)))
  853.    ((eq? (car sent) 'WHATMEANS)
  854.     (doctor-def (doctor-cadr sent)))
  855.    ((equal? sent '(PARSE))
  856.     (doctor-type (list  'SUBJ '= subj ",  "
  857.             'VERB '= verb #\NEWLINE
  858.             'OBJECT 'PHRASE '= obj ","
  859.             'NOUN 'FORM '=  object #\NEWLINE
  860.             'CURRENT 'KEYWORD 'IS found
  861.             ", "
  862.             'MOST 'RECENT 'POSSESSIVE
  863.             'IS owner #\NEWLINE
  864.             'SENTENCE 'USED 'WAS
  865.             "..."
  866.             '(// bak))))
  867.    ;;   ((eq? (car sent) 'FORGET)
  868.    ;;    (set (doctor-cadr sent) #F)
  869.    ;;    (doctor-type '(($ isee) ($ please)
  870.    ;;     ($ continue)|.|)))
  871.    (else
  872.     (if (doctor-defq sent) (doctor-define sent found))
  873.     (if (> (length sent) 12) (doctor-shorten))
  874.     (set! sent (doctor-correct-spelling (doctor-replace sent replist)))
  875.     (cond ((and (not (memq 'ME sent)) (not (memq 'I sent))
  876.         (memq 'AM sent))
  877.        (set! sent (doctor-replace sent '((AM . (ARE)))))))
  878.     (cond ((equal? (car sent) 'YOW) (doctor-zippy))
  879.       ((< (length sent) 2)
  880.        (cond ((eq? (doctor-meaning (car sent)) 'HOWDY)
  881.           (doctor-howdy))
  882.          (else (doctor-short))))
  883.       (else
  884.        (if (memq 'AM sent)
  885.            (set! sent (doctor-replace sent '((ME . (I))))))
  886.        (set! sent (doctor-fixup sent))
  887.        (if (and (eq? (car sent) 'DO) (eq? (doctor-cadr sent) 'NOT))
  888.            (cond ((zero? (random 3))
  889.               (doctor-type '(ARE YOU ($ afraidof) THAT ?)))
  890.              ((zero? (random 2))
  891.               (doctor-type '(|DON'T| TELL ME WHAT TO DO |.| I AM THE
  892.                         PSYCHIATRIST HERE!))
  893.               (doctor-rthing))
  894.              (else
  895.               (doctor-type '(($ whysay) THAT I |SHOULDN'T|
  896.                      (doctor-cddr sent)
  897.                      ?))))
  898.          (doctor-go (doctor-wherego sent))))))))
  899.  
  900. ;; Things done to process sentences once read.
  901.  
  902. (define (doctor-correct-spelling sent)
  903.   "Correct the spelling and expand each word in sentence."
  904.   (if sent
  905.       (apply append (mapcar (lambda (word)
  906.                   (if (memq word typos)
  907.                   (getprop (getprop word 'DOCTOR-CORRECTION) 'DOCTOR-EXPANSION)
  908.                   (list word)))
  909.                 sent))))
  910.  
  911. (define (doctor-shorten)
  912.   "Make a sentence manageably short using a few hacks."
  913.   (let ((foo '())
  914.     (retval '())
  915.     (temp '(BECAUSE BUT HOWEVER BESIDES ANYWAY UNTIL
  916.             WHILE THAT EXCEPT WHY HOW)))
  917.     (while temp
  918.        (set! foo (memq (car temp) sent))
  919.        (if (and foo
  920.             (> (length foo) 3))
  921.            (begin (set! sent foo)
  922.               (set! sent (doctor-fixup sent))
  923.               (set! temp #F)
  924.               (set! retval #T))
  925.            (set! temp (cdr temp))))
  926.     retval))
  927.  
  928. (define (doctor-define sent found)
  929.   (doctor-svo sent found 1 #F)
  930.   (and
  931.     (doctor-nounp subj)
  932.     (not (doctor-pronounp subj))
  933.     subj
  934.     (doctor-meaning object)
  935.     (putprop subj (doctor-meaning object) 'DOCTOR-MEANING)
  936.     #T))
  937.  
  938. (define (doctor-defq sent)
  939.   "Set global var FOUND to first keyword found in sentence SENT."
  940.   (set! found #F)
  941.   (let ((temp '(MEANS APPLIES MEAN REFERS REFER RELATED
  942.               SIMILAR DEFINED ASSOCIATED LINKED LIKE SAME)))
  943.     (while temp
  944.        (if (memq (car temp) sent)
  945.            (begin (set! found (car temp))
  946.               (set! temp #F))
  947.            (set! temp (cdr temp)))))
  948.   found)
  949.  
  950. (define (doctor-def x)
  951.   (doctor-type (list 'THE 'WORD x 'MEANS (doctor-meaning x) 'TO 'ME)) 
  952.   #F)
  953.  
  954. (define (doctor-forget)
  955.   "Delete the last element of the history list."
  956.   (set! history (reverse (cdr (reverse history)))))
  957.  
  958. (define (doctor-query x)
  959.   "Prompt for a line of input from the minibuffer until a noun or verb is seen.
  960. Put dialogue in buffer."
  961.   (let ((a '())
  962.     (prompt (string-append (doctor-make-string x)
  963.             " what ?  "))
  964.     (retval '()))
  965.     (while (not retval)
  966.        (while (not a)
  967.          (insert #\newline
  968.              prompt
  969.              (read-string prompt)
  970.              #\newline)
  971.          (set! a (doctor-readin)))
  972.        (while (and a (not retval))
  973.           (cond ((doctor-nounp (car a))
  974.              (set! retval (car a)))
  975.             ((doctor-verbp (car a))
  976.              (set! retval (doctor-build
  977.                        (doctor-build x " ")
  978.                        (car a))))
  979.             ((set! a (cdr a))))))
  980.     retval))
  981.  
  982. (define (doctor-subjsearch sent key type)
  983.   "Search for the subject of a sentence SENT, looking for the noun closest
  984. to and preceding KEY by at least TYPE words.  Set global variable subj to
  985. the subject noun, and return the portion of the sentence following it."
  986.   (let ((i (- (length sent) (length (memq key sent)) type)))
  987.     (while (and (> i -1) (not (doctor-nounp (list-ref sent i))))
  988.       (set! i (-1+ i)))
  989.     (cond ((> i -1)
  990.        (set! subj (list-ref sent i))
  991.        (list-tail sent (1+ i)))
  992.       (else
  993.        (set! subj 'YOU)
  994.        #F))))
  995.  
  996. (define (doctor-nounp x)
  997.   "Returns t if the symbol argument is a noun."
  998.     (or (doctor-pronounp x)
  999.         (not (or (doctor-verbp x)
  1000.              (equal? x 'NOT)
  1001.              (doctor-prepp x)
  1002.              (doctor-modifierp x) )) ))
  1003.  
  1004. (define (doctor-pronounp x)
  1005.   "Returns t if the symbol argument is a pronoun."
  1006.   (memq x '(
  1007.     I ME MINE MYSELF
  1008.     WE US OURS OURSELVES OURSELF
  1009.     YOU YOURS YOURSELF YOURSELVES
  1010.     HE HIM HIMSELF SHE HERS HERSELF
  1011.     IT THAT THOSE THIS THESE THINGS THING
  1012.     THEY THEM THEMSELVES THEIRS
  1013.     ANYBODY EVERYBODY SOMEBODY
  1014.     ANYONE EVERYONE SOMEONE
  1015.     ANYTHING SOMETHING EVERYTHING)))
  1016.  
  1017. (mapcar (lambda (x) (putprop x 'VERB 'DOCTOR-SENTENCE-TYPE))
  1018.     '(ABORT ABORTED ABORTS ASK ASKED ASKS AM
  1019.         APPLIED APPLIES APPLY ARE ASSOCIATE
  1020.         ASSOCIATED ATE
  1021.         BE BECAME BECOME BECOMES BECOMING
  1022.         BEEN BEING BELIEVE BELIEVED BELIEVES
  1023.         BIT BITE BITES BORE BORED BORES BORING BOUGHT BUY BUYS BUYING
  1024.         CALL CALLED CALLING CALLS CAME CAN CAUGHT CATCH COME
  1025.         CONTRACT CONTRACTED CONTRACTS CONTROL CONTROLLED CONTROLS
  1026.         COULD CROAK CROAKS CROAKED CUT CUTS
  1027.         DARE DARED DEFINE DEFINES DIAL DIALED DIALS DID DIE DIED DIES
  1028.         DISLIKE DISLIKED
  1029.         DISLIKES DO DOES DRANK DRINK DRINKS DRINKING
  1030.         DRIVE DRIVES DRIVING DROVE DYING
  1031.         EAT EATING EATS EXPAND EXPANDED EXPANDS
  1032.         EXPECT EXPECTED EXPECTS EXPEL EXPELS EXPELLED
  1033.         EXPLAIN EXPLAINED EXPLAINS
  1034.         FART FARTS FEEL FEELS FELT FIGHT FIGHTS FIND FINDS FINDING
  1035.         FORGET FORGETS FORGOT FOUGHT FOUND FUCK FUCKED
  1036.         FUCKING FUCKS
  1037.         GAVE GET GETS GETTING GIVE GIVES GO GOES GOING GONE GOT GOTTEN
  1038.         HAD HARM HARMS HAS HATE HATED HATES HAVE HAVING
  1039.         HEAR HEARD HEARS HEARING HELP HELPED HELPING HELPS
  1040.         HIT HITS HOPE HOPED HOPES HURT HURTS
  1041.         IMPLIES IMPLY IS
  1042.         JOIN JOINED JOINS JUMP JUMPED JUMPS
  1043.         KEEP KEEPING KEEPS KEPT
  1044.         KILL KILLED KILLING KILLS KISS KISSED KISSES KISSING
  1045.         KNEW KNOW KNOWS
  1046.         LAID LAY LAYS LET LETS LIE LIED LIES LIKE LIKED LIKES
  1047.         LIKING LISTEN LISTENS
  1048.         LOGIN LOOK LOOKED LOOKING LOOKS
  1049.         LOSE LOSING LOST
  1050.         LOVE LOVED LOVES LOVING
  1051.         LUSE LUSING LUST LUSTS
  1052.         MADE MAKE MAKES MAKING MAY MEAN MEANS MEANT MIGHT
  1053.         MOVE MOVED MOVES MOVING MUST
  1054.         NEED NEEDED NEEDS 
  1055.         ORDER ORDERED ORDERS OUGHT
  1056.         PAID PAY PAYS PICK PICKED PICKING PICKS 
  1057.         PLACED PLACING PREFER PREFERS PUT PUTS
  1058.         RAN RAPE RAPED RAPES
  1059.         READ READING READS RECALL RECEIVE RECEIVED RECEIVES
  1060.         REFER REFERED REFERRED REFERS
  1061.         RELATE RELATED RELATES REMEMBER REMEMBERED REMEMBERS
  1062.         ROMP ROMPED ROMPS RUN RUNNING RUNS
  1063.         SAID SANG SAT SAW SAY SAYS
  1064.         SCREW SCREWED SCREWING SCREWS SCROD SEE SEES SEEM SEEMED
  1065.         SEEMS SEEN SELL SELLING SELLS
  1066.         SEND SENDIND SENDS SENT SHALL SHOOT SHOT SHOULD
  1067.         SING SINGS SIT SITS SITTING SOLD STUDIED STUDY
  1068.         TAKE TAKES TAKING TALK TALKED TALKING TALKS TELL TELLS TELLING
  1069.         THINK THINKS
  1070.         THOUGHT TOLD TOOK TOOLED TOUCH TOUCHED TOUCHES TOUCHING
  1071.         TRANSFER TRANSFERRED TRANSFERS TRANSMIT TRANSMITS TRANSMITTED
  1072.         TYPE TYPES TYPES TYPING
  1073.         WALK WALKED WALKING WALKS WANT WANTED WANTS WAS WATCH
  1074.         WATCHED WATCHING WENT WERE WILL WISH WOULD WORK WORKED WORKS
  1075.         WRITE WRITES WRITING WROTE USE USED USES USING))
  1076.  
  1077. (define (doctor-verbp x) (if (symbol? x)
  1078.                 (eq? (getprop x 'DOCTOR-SENTENCE-TYPE) 'VERB)))
  1079.  
  1080. (define (doctor-plural x)
  1081.   "Form the plural of the word argument."
  1082.   (let ((foo (doctor-make-string x)))
  1083.     (cond ((string=? (doctor-substring foo -1) "S")
  1084.        (cond ((string=? (doctor-substring foo -2 -1) "S")
  1085.           (string->symbol (string-append foo "ES")))
  1086.          (else x)))
  1087.        ((string=? (doctor-substring foo -1) "Y")
  1088.         (string->symbol (string-append (doctor-substring foo 0 -1)
  1089.                 "IES")))
  1090.        (else (string->symbol (string-append foo "S"))))))
  1091.  
  1092. (define (doctor-setprep sent key)
  1093.   (let ((val '())
  1094.     (foo (memq key sent)))
  1095.     (cond ((doctor-prepp (doctor-cadr foo))
  1096.        (set! val (doctor-getnoun (doctor-cddr foo)))
  1097.        (cond (val val)
  1098.          (else 'SOMETHING)))
  1099.       ((doctor-articlep (doctor-cadr foo))
  1100.        (set! val (doctor-getnoun (doctor-cddr foo)))
  1101.        (cond (val (doctor-build (doctor-build (doctor-cadr foo) " ") val))
  1102.          (else 'SOMETHING)))
  1103.       (else 'SOMETHING))))
  1104.  
  1105. (define (doctor-getnoun x)
  1106.   (cond ((null? x) (set! object 'SOMETHING))
  1107.     ((atom? x) (set! object x))
  1108.     ((eq? (length x) 1)
  1109.      (set! object (cond
  1110.                ((doctor-nounp (set! object (car x))) object)
  1111.                (else (doctor-query object)))))
  1112.     ((eq? (car x) 'TO)
  1113.      (doctor-build '|TO | (doctor-getnoun (cdr x))))
  1114.     ((doctor-prepp (car x))
  1115.      (doctor-getnoun (cdr x)))
  1116.     ((not (doctor-nounp (car x)))
  1117.      (doctor-build (doctor-build (cdr (assq (car x)
  1118.                         (append
  1119.                          '((A . THIS)
  1120.                            (SOME . THIS)
  1121.                            (ONE . THAT))
  1122.                          (list
  1123.                           (cons
  1124.                            (car x) (car x))))))
  1125.                      " ")
  1126.                (doctor-getnoun (cdr x))))
  1127.     (else (set! object (car x))) ))
  1128.  
  1129. (define (doctor-modifierp x)
  1130.   (or (doctor-adjectivep x)
  1131.       (doctor-adverbp x)
  1132.       (doctor-othermodifierp x)))
  1133.  
  1134. (define (doctor-adjectivep x)
  1135.   (or (number? x)
  1136.       (doctor-nmbrp x)
  1137.       (doctor-articlep x)
  1138.       (doctor-colorp x)
  1139.       (doctor-sizep x)
  1140.       (doctor-possessivepronounp x)))
  1141.  
  1142. (define (doctor-adverbp xx)
  1143.   (string=? (doctor-substring (doctor-make-string xx) -2) "LY"))
  1144.  
  1145. (define (doctor-articlep x)
  1146.   (memq x '(THE A AN)))
  1147.  
  1148. (define (doctor-nmbrp x)
  1149.   (memq x '(ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE TEN
  1150.         ELEVEN TWELVE THIRTEEN FOURTEEN FIFTEEN
  1151.         SIXTEEN SEVENTEEN EIGHTEEN NINETEEN
  1152.         TWENTY THIRTY FORTY FIFTY SIXTY SEVENTY EIGHTY NINETY
  1153.         HUNDRED THOUSAND MILLION BILLION
  1154.         HALF QUARTER
  1155.         FIRST SECOND THIRD FOURTH FIFTH
  1156.         SIXTH SEVENTH EIGHTH NINTH TENTH)))
  1157.          
  1158. (define (doctor-colorp x)
  1159.   (memq x '(BEIGE BLACK BLUE BROWN CRIMSON
  1160.           GRAY GREY GREEN
  1161.           ORANGE PINK PURPLE RED TAN TAWNY
  1162.           VIOLET WHITE YELLOW)))
  1163.  
  1164. (define (doctor-sizep x)
  1165.   (memq x '(BIG LARGE TALL FAT WIDE THICK
  1166.         SMALL PETITE SHORT THIN SKINNY)))
  1167.  
  1168. (define (doctor-possessivepronounp x)
  1169.   (memq x '(MY YOUR HIS HER OUR THEIR)))
  1170.  
  1171. (define (doctor-othermodifierp x)
  1172.   (memq x '(ALL ALSO ALWAYS AMUSING ANY ANYWAY ASSOCIATED AWESOME
  1173.         BAD BEAUTIFUL BEST BETTER BUT CERTAIN CLEAR
  1174.         EVER EVERY FANTASTIC FUN FUNNY
  1175.         GOOD GREAT GROSS GROWDY HOWEVER IF IGNORANT
  1176.         LESS LINKED LOSING LUSING MANY MORE MUCH
  1177.         NEVER NICE OBNOXIOUS OFTEN POOR PRETTY REAL RELATED RICH
  1178.         SIMILAR SOME STUPID SUPER SUPERB
  1179.         TERRIBLE TERRIFIC TOO TOTAL TUBULAR UGLY VERY)))
  1180.  
  1181. (define (doctor-prepp x)
  1182.   (memq x '(ABOUT ABOVE AFTER AROUND AS AT
  1183.           BEFORE BENEATH BEHIND BESIDE BETWEEN BY
  1184.           FOR FROM IN INSIDE INTO
  1185.           LIKE NEAR NEXT OF ON ONTO OVER
  1186.           SAME THROUGH THRU TO TOWARD TOWARDS
  1187.           UNDER UNDERNEATH WITH WITHOUT)))
  1188.  
  1189. (define (doctor-remember thing)
  1190.   (cond ((null? history)
  1191.      (set! history (list thing)))
  1192.     (else (set! history (append history (list thing))))))
  1193.  
  1194. (define (doctor-type x)
  1195.   (set! x (doctor-fix-2 x))
  1196.   (doctor-txtype (doctor-assm x)))
  1197.  
  1198. (define (doctor-fixup sent)
  1199.   (set! sent (append
  1200.           (cdr
  1201.            (assq (car sent)
  1202.              (append
  1203.               '((ME  I)
  1204.             (HIM  HE)
  1205.             (HER  SHE)
  1206.             (THEM  THEY)
  1207.             (OKAY)
  1208.             (WELL)
  1209.             (SIGH)
  1210.             (HMM)
  1211.             (HMMM)
  1212.             (HMMMM)
  1213.             (HMMMMM)
  1214.             (GEE)
  1215.             (SURE)
  1216.             (GREAT)
  1217.             (OH)
  1218.             (FINE)
  1219.             (OK)
  1220.             (NO))
  1221.               (list (list (car sent)
  1222.                   (car sent))))))
  1223.           (cdr sent)))
  1224.   (doctor-fix-2 sent))
  1225.  
  1226. (define (doctor-fix-2 sent)
  1227.   (let ((foo sent))
  1228.     (while foo
  1229.       (if (and (eq? (car foo) 'ME)
  1230.            (doctor-verbp (doctor-cadr foo)))
  1231.       (set-car! foo 'I)
  1232.       (begin
  1233.     (cond ((eq? (car foo) 'YOU)
  1234.            (cond ((memq (doctor-cadr foo) '(AM BE BEEN IS))
  1235.               (set-car! (cdr foo) 'ARE))
  1236.              ((memq (doctor-cadr foo) '(HAS))
  1237.               (set-car! (cdr foo) 'HAVE))
  1238.              ((memq (doctor-cadr foo) '(WAS))
  1239.               (set-car! (cdr foo) 'WERE))))
  1240.           ((equal? (car foo) 'I)
  1241.            (cond ((memq (doctor-cadr foo) '(ARE IS BE BEEN))
  1242.               (set-car! (cdr foo) 'AM))
  1243.              ((memq (doctor-cadr foo) '(WERE))
  1244.               (set-car! (cdr foo) 'WAS))
  1245.              ((memq (doctor-cadr foo) '(HAS))
  1246.               (set-car! (cdr foo) 'HAVE))))
  1247.           ((and (doctor-verbp (car foo))
  1248.             (eq? (doctor-cadr foo) 'I)
  1249.             (not (doctor-verbp (car (doctor-cddr foo)))))
  1250.            (set-car! (cdr foo) 'ME))
  1251.           ((and (eq? (car foo) 'A)
  1252.             (doctor-vowelp (string-ref (doctor-make-string (doctor-cadr foo)) 0)
  1253.             ))
  1254.            (set-car! foo 'AN))
  1255.           ((and (eq? (car foo) 'AN)
  1256.             (not (doctor-vowelp (string-ref (doctor-make-string (doctor-cadr foo)) 0)
  1257.              )))
  1258.            (set-car! foo 'A)))
  1259.         (set! foo (cdr foo)))))
  1260.     sent))
  1261.  
  1262. (define (doctor-vowelp x)
  1263.   (memq (char-upcase x) '(#\A #\E #\I #\O #\U)))
  1264.  
  1265. (define (doctor-replace sent rlist)
  1266.   "Replace any element of SENT that is the car of a replacement
  1267. element pair in RLIST."
  1268.   (apply append
  1269.      (mapcar
  1270.        (lambda (x)
  1271.          (cdr (or (assq x rlist)   ; either find a replacement
  1272.               (list x x))))    ; or fake an identity mapping
  1273.       sent)))
  1274.  
  1275. (define (doctor-wherego sent)
  1276.   (cond ((null? sent) ($ whereoutp))
  1277.     ((null? (doctor-meaning (car sent)))
  1278.      (doctor-wherego (cond ((zero? (random 2))
  1279.                 (reverse (cdr sent)))
  1280.                    (else (cdr sent)))))
  1281.     (else
  1282.      (set! found (car sent))
  1283.      (doctor-meaning (car sent)))))
  1284.  
  1285. (define (doctor-svo sent key type mem)
  1286.   "Find subject, verb and object in sentence SENT with focus on word KEY.
  1287. TYPE is number of words preceding KEY to start looking for subject.
  1288. MEM is t if results are to be put on Doctor's memory stack.
  1289. Return in the global variables SUBJ, VERB and OBJECT."
  1290.   (let ((foo (doctor-subjsearch sent key type)))
  1291.     (or foo
  1292.     (begin (set! foo sent)
  1293.            (set! mem #F)))
  1294.     (while (and (null? (doctor-verbp (car foo))) (cdr foo))
  1295.       (set! foo (cdr foo)))
  1296.     (set! verb (car foo))
  1297.     (set! obj (doctor-getnoun (cdr foo)))
  1298.     (cond ((eq? object 'I) (set! object 'ME))
  1299.       ((eq? subj 'ME) (set! subj 'I)))
  1300.     (cond (mem (doctor-remember (list subj verb obj))))))
  1301.  
  1302. (define (doctor-possess sent key)
  1303.   "Set possessive in SENT for keyword KEY.
  1304. Hack on previous word, setting global variable OWNER to correct result."
  1305.   (let* ((i (- (length sent) (length (memq key sent)) 1))
  1306.      (prev (if (< i 0) 'YOUR
  1307.          (list-ref sent i))))
  1308.     (set! owner (if (or (doctor-possessivepronounp prev)
  1309.             (string=? "S"
  1310.                       (doctor-substring (doctor-make-string prev)
  1311.                          -1)))
  1312.             prev
  1313.           'YOUR))))
  1314.  
  1315. ;; Output of replies.
  1316.  
  1317. (define (doctor-txtype ans)
  1318.   "Output to buffer a list of symbols or strings as a sentence."
  1319.   (set! *print-upcase* #T)
  1320.   (set! *print-space* #F)
  1321.   (mapcar doctor-type-symbol ans)
  1322.   (insert #\newline))
  1323.  
  1324. (define (doctor-type-symbol word)
  1325.   "Output a symbol to the buffer with some fancy case and spacing hacks."
  1326.   (set! word (doctor-make-string word))
  1327.   (if (string=? word "I") (set! word "I"))
  1328.   (if *print-upcase*
  1329.       (begin
  1330.     (set! word (capitalize word))
  1331.     (if *print-space*
  1332.         (insert " "))))
  1333.   (cond ((or (substring-find-next-char-in-set word 0 (min 1 (string-length word)) ".,;:?! ")
  1334.          (not *print-space*))
  1335.      (insert word))
  1336.     (else (insert #\space word)))
  1337.   (set! *print-upcase* (substring-find-next-char-in-set
  1338.              word (max 0 (-1+ (string-length word)))
  1339.              (string-length word) "[.?!]$"))
  1340.   (set! *print-space* #T))
  1341.  
  1342. (define (doctor-build str1 str2)
  1343.   "Make a symbol out of the concatenation of the two non-list arguments."
  1344.   (cond ((null? str1) str2)
  1345.     ((null? str2) str1)
  1346.     ((and (atom? str1)
  1347.           (atom? str2))
  1348.      (string->symbol (string-append (doctor-make-string str1)
  1349.              (doctor-make-string str2))))
  1350.     (else #F)))
  1351.  
  1352. (define (doctor-make-string obj)
  1353.   (cond ((string? obj) obj)
  1354.     ((symbol? obj) (symbol->string obj))
  1355.     ((number? obj) (number->string obj))
  1356.     (else "")))
  1357.  
  1358. (define (doctor-concat x y)
  1359.   "Like append, but force atomic arguments to be lists."
  1360.   (append
  1361.    (if (and x (atom? x)) (list x) x)
  1362.    (if (and y (atom? y)) (list y) y)))
  1363.  
  1364. (define (doctor-assm proto)
  1365.   (cond ((null? proto) #F)
  1366.     ((atom? proto) (list proto))
  1367.     ((atom? (car proto))
  1368.      (cons (car proto) (doctor-assm (cdr proto))))
  1369.     (else (doctor-concat (doctor-assm (eval (car proto))) (doctor-assm (cdr proto))))))
  1370.  
  1371. ;; Functions that handle specific words or meanings when found.
  1372.  
  1373. (define (doctor-go destination)
  1374.   "Call a `doctor-*' function."
  1375.   (eval (list (string->symbol (string-append "DOCTOR-" (doctor-make-string destination))))))
  1376.  
  1377. (define (doctor-desire1)
  1378.   (doctor-go ($ whereoutp)))
  1379.  
  1380. (define (doctor-huh)
  1381.   (cond ((< (length sent) 9) (doctor-type ($ huhlst)))
  1382.     (else (doctor-type ($ longhuhlst)))))
  1383.  
  1384. (define (doctor-rthing) (doctor-type ($ thlst)))
  1385.  
  1386. (define (doctor-remem) (cond ((null? history) (doctor-huh))
  1387.                  ((doctor-type ($ remlst)))))
  1388.  
  1389. (define (doctor-howdy)
  1390.   (cond ((not howdyflag)
  1391.      (doctor-type '(($ hello) WHAT BRINGS YOU TO SEE ME ?))
  1392.      (set! howdyflag #T))
  1393.     (else
  1394.      (doctor-type '(($ ibelieve) |WE'VE| INTRODUCED OURSELVES ALREADY |.|))
  1395.      (doctor-type '(($ please) ($ describe) ($ things) |.|)))))
  1396.  
  1397. (define (doctor-when)
  1398.   (cond ((< (length (memq found sent)) 3) (doctor-short))
  1399.     (else
  1400.      (set! sent (cdr (memq found sent)))
  1401.      (set! sent (doctor-fixup sent))
  1402.      (doctor-type '(($ whatwhen) (// sent) ?)))))
  1403.  
  1404. (define (doctor-conj)
  1405.   (cond ((< (length (memq found sent)) 4) (doctor-short))
  1406.     (else
  1407.      (set! sent (cdr (memq found sent)))
  1408.      (set! sent (doctor-fixup sent))
  1409.      (cond ((eq? (car sent) 'OF)
  1410.         (doctor-type '(ARE YOU ($ sure) THAT IS THE REAL REASON ?))
  1411.         (set! things (cons (cdr sent) things)))
  1412.            (else
  1413.         (doctor-remember sent)
  1414.         (doctor-type ($ beclst)))))))
  1415.  
  1416. (define (doctor-short)
  1417.   (cond ((= (car repetitive-shortness) (-1+ lincount))
  1418.      (set-cdr! repetitive-shortness
  1419.          (1+ (cdr repetitive-shortness))))
  1420.     (else
  1421.      (set-cdr! repetitive-shortness 1)))
  1422.   (set-car! repetitive-shortness lincount)
  1423.   (cond ((> (cdr repetitive-shortness) 6)
  1424.      (cond ((not **mad**)
  1425.         (doctor-type '(($ areyou)
  1426.                    JUST TRYING TO SEE WHAT KIND OF THINGS
  1427.                    I HAVE IN MY VOCABULARY ? PLEASE TRY TO
  1428.                    CARRY ON A REASONABLE CONVERSATION!))
  1429.         (set! **mad** #T))
  1430.            (else
  1431.         (doctor-type '(I GIVE UP |.| YOU NEED A LESSON IN CREATIVE
  1432.                  WRITING |...|))
  1433.         ;;(push monosyllables observation-list)
  1434.         )))
  1435.     (else
  1436.      (cond ((equal? sent (doctor-assm '(YES)))
  1437.         (doctor-type '(($ isee) ($ inter) ($ whysay) THIS IS SO ?)))
  1438.            ((equal? sent (doctor-assm '(BECAUSE)))
  1439.         (doctor-type ($ shortbeclst)))
  1440.            ((equal? sent (doctor-assm '(NO)))
  1441.         (doctor-type ($ neglst)))
  1442.            (else (doctor-type ($ shortlst)))))))
  1443.        
  1444. (define (doctor-alcohol) (doctor-type ($ drnk)))
  1445.  
  1446. (define (doctor-desire)
  1447.   (let ((foo (memq found sent)))
  1448.     (cond ((< (length foo) 2)
  1449.        (doctor-go (doctor-build (doctor-meaning found) 1)))
  1450.       ((memq (doctor-cadr foo) '(A AN))
  1451.        (set-cdr! foo (append '(TO HAVE) (cdr foo)))
  1452.        (doctor-svo sent found 1 #F)
  1453.        (doctor-remember (list subj 'WOULD 'LIKE obj))
  1454.        (doctor-type ($ whywant)))
  1455.       ((not (eq? (doctor-cadr foo) 'TO))
  1456.        (doctor-go (doctor-build (doctor-meaning found) 1)))
  1457.       (else
  1458.        (doctor-svo sent found 1 #F)
  1459.        (doctor-remember (list subj 'WOULD 'LIKE obj))
  1460.        (doctor-type ($ whywant))))))
  1461.  
  1462. (define (doctor-drug)
  1463.   (doctor-type ($ drugs))
  1464.   (doctor-remember (list 'YOU 'USED found)))
  1465.  
  1466. (define (doctor-toke)
  1467.   (doctor-type ($ toklst)))
  1468.  
  1469. (define (doctor-state)
  1470.   (doctor-type ($ states)) (doctor-remember (lisT 'YOU 'WERE found)))
  1471.  
  1472. (define (doctor-mood)
  1473.   (doctor-type ($ moods)) (doctor-remember (list 'YOU 'FELT found)))
  1474.  
  1475. (define (doctor-fear)
  1476.   (set! feared (doctor-setprep sent found))
  1477.   (doctor-type ($ fears))
  1478.   (doctor-remember (list 'YOU 'WERE 'AFRAID 'OF feared)))
  1479.  
  1480. (define (doctor-hate)
  1481.   (doctor-svo sent found 1 #T)
  1482.   (cond ((memq 'NOT sent) (doctor-forget) (doctor-huh))
  1483.     ((equal? subj 'YOU)
  1484.      (doctor-type '(WHY DO YOU (// verb) (// obj) ?)))
  1485.     (else (doctor-type '(($ whysay) (list subj verb obj))))))
  1486.  
  1487. (define (doctor-symptoms)
  1488.   (doctor-type '(($ maybe) YOU SHOULD CONSULT A DOCTOR OF |MEDICINE,|
  1489.          I AM A PSYCHIATRIST |.|)))
  1490.  
  1491. (define (doctor-hates)
  1492.   (doctor-svo sent found 1 #T)
  1493.   (doctor-hates1))
  1494.  
  1495. (define (doctor-hates1)
  1496.   (doctor-type '(($ whysay) (list subj verb obj))))
  1497.  
  1498. (define (doctor-loves)
  1499.   (doctor-svo sent found 1 #T)
  1500.   (doctor-qloves))
  1501.  
  1502. (define (doctor-qloves)
  1503.   (doctor-type '(($ bother) (list subj verb obj) ?)))
  1504.  
  1505. (define (doctor-love)
  1506.   (doctor-svo sent found 1 #T)
  1507.   (cond ((memq 'NOT sent) (doctor-forget) (doctor-huh))
  1508.     ((memq 'TO sent) (doctor-hates1))
  1509.     (else
  1510.      (cond ((equal? object 'SOMETHING)
  1511.         (set! object '(THIS PERSON YOU LOVE))))
  1512.      (cond ((equal? subj 'YOU)
  1513.         (set! lover obj)
  1514.         (cond ((equal? lover '(THIS PERSON YOU LOVE))
  1515.                (set! lover '(YOUR PARTNER))
  1516.                (doctor-forget)
  1517.                (doctor-type '(WITH WHOM ARE YOU IN LOVE ?)))
  1518.               ((doctor-type '(($ please)
  1519.                       ($ describe)
  1520.                       ($ relation)
  1521.                       (// lover)
  1522.                       |.|)))))
  1523.            ((equal? subj 'I)
  1524.         (doctor-txtype '(WE WERE DISCUSSING YOU!)))
  1525.            (else (doctor-forget)
  1526.           (set! obj 'SOMEONE)
  1527.           (set! verb (doctor-build verb 'S))
  1528.           (doctor-qloves))))))
  1529.  
  1530. (define (doctor-mach)
  1531.   (set! found (doctor-plural found))
  1532.   (doctor-type ($ machlst)))
  1533.  
  1534. (define (doctor-sexnoun) (doctor-sexverb))
  1535.  
  1536. (define (doctor-sexverb)
  1537.   (if (or (memq 'ME sent) (memq 'MYSELF sent) (memq 'I sent))
  1538.       (doctor-foul)
  1539.     (doctor-type ($ sexlst))))
  1540.  
  1541. (define (doctor-death) (doctor-type ($ deathlst)))
  1542.  
  1543. (define (doctor-foul)
  1544.   (doctor-type ($ foullst)))
  1545.  
  1546. (define (doctor-family)
  1547.   (doctor-possess sent found)
  1548.   (doctor-type ($ famlst)))
  1549.  
  1550. ;; I did not add this -- rms.
  1551. ;; But he might have removed it.  I put it back.  --roland
  1552. (define (doctor-rms)
  1553.   (cond (rms-flag (doctor-type ($ stallmanlst)))
  1554.     (else (set! rms-flag #T) (doctor-type '(DO YOU KNOW STALLMAN ?)))))
  1555.  
  1556. (define (doctor-school) (doctor-type ($ schoollst)))
  1557.  
  1558. (define (doctor-eliza)
  1559.   (cond (eliza-flag (doctor-type ($ elizalst)))
  1560.     (else (set! eliza-flag #T)
  1561.           (doctor-type '((// found) ? HAH !
  1562.                  ($ please) ($ continue) |.|)))))
  1563.  
  1564. (define (doctor-sports)  (doctor-type ($ sportslst)))
  1565.  
  1566. (define (doctor-math) (doctor-type ($ mathlst)))
  1567.  
  1568. (define (doctor-zippy)
  1569.   (cond (zippy-flag (doctor-type ($ zippylst)))
  1570.     (else (set! zippy-flag #T)
  1571.        (doctor-type '(YOW! ARE WE INTERACTIVE YET ?)))))
  1572.  
  1573.  
  1574. (define (doctor-chat) (doctor-type ($ chatlst)))
  1575.  
  1576. (define (doctor-strangelove)
  1577.   (interactive)
  1578.   (insert "MEIN FUHRER!!\N")
  1579.   (doctor-read-print))
  1580.  
  1581. ;;; doctor.el ends here
  1582.  
  1583. (define (doctor)
  1584.   (make-doctor-variables)
  1585.   (doctor-type '(I AM THE PSYCHOTHERAPIST |.|
  1586.          ($ please) ($ describe) YOUR ($ problems) |.|
  1587.          EACH TIME YOU ARE FINISHED |TALKING,| TYPE |<RET>.|))
  1588.   (insert #\newline)
  1589.   (let loop ()
  1590.     (doctor-read-print)
  1591.     (loop)))
  1592.  
  1593.